/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.agenda.client.view;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import com.agenda.PrincipalCliente;
import com.agenda.client.ClienteServidor;
import com.agenda.client.listeners.UsuariosSelecionadosListener;
import com.agenda.client.requisicoes.AtualizarStatusCompromissoRequisicao;
import com.agenda.client.requisicoes.EnviarCompromissoRequisicao;
import com.agenda.client.requisicoes.VerificarChoqueCompromissoRequisicao;
import com.agenda.comum.EnvioInformacao;
import com.agenda.comum.ObjectEnvioInformacao;
import com.agenda.model.AnexoCompromisso;
import com.agenda.model.Compromisso;
import com.agenda.model.Convite;
import com.agenda.model.Requisicao;
import com.agenda.model.RequisicaoEnum;
import com.agenda.model.RespostaRequisicao;
import com.agenda.model.Usuario;
import com.agenda.util.FileUtil;
import com.agenda.util.StringUtils;

/**
 *
 * @author Murilo
 */
public class CompromissoDialogView extends javax.swing.JDialog implements UsuariosSelecionadosListener {

	/**
	 * Creates new form CompromissoDialogView
	 */
	public CompromissoDialogView(java.awt.Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of
	 * this method is always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jPanel1 = new javax.swing.JPanel();
		dataText = new javax.swing.JFormattedTextField();
		jLabel1 = new javax.swing.JLabel();
		jLabel3 = new javax.swing.JLabel();
		dataFinalText = new javax.swing.JFormattedTextField();
		jScrollPane2 = new javax.swing.JScrollPane();
		descricaoText = new javax.swing.JTextArea();
		jLabel4 = new javax.swing.JLabel();
		nomeText = new javax.swing.JTextField();
		jLabel5 = new javax.swing.JLabel();
		jPanel3 = new javax.swing.JPanel();
		adicionarUsuario = new javax.swing.JButton();
		removerUsuario = new javax.swing.JButton();
		jPanel2 = new javax.swing.JPanel();
		jPanel4 = new javax.swing.JPanel();
		confirmarButton = new javax.swing.JButton();
		cancelarButton = new javax.swing.JButton();
		jScrollPane3 = new javax.swing.JScrollPane();
		arquivosJList = new javax.swing.JList();
		jPanel5 = new javax.swing.JPanel();
		adicionarArquivoButton = new javax.swing.JButton();
		removerArquivoButton = new javax.swing.JButton();
		downloadArquivoButton = new javax.swing.JButton();
		jScrollPane1 = new javax.swing.JScrollPane();
		contatosTable = new javax.swing.JTable();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setTitle("Compromisso");
		getContentPane().setLayout(new java.awt.BorderLayout(0, 5));

		jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
		jPanel1.setPreferredSize(new java.awt.Dimension(468, 250));

		dataText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));

		jLabel1.setText("Data Inicial");

		jLabel3.setText("Data Final");

		dataFinalText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));

		descricaoText.setColumns(20);
		descricaoText.setRows(5);
		jScrollPane2.setViewportView(descricaoText);

		jLabel4.setText("Nome");

		jLabel5.setText("Descrição");

		jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

		adicionarUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/agenda/client/view/imagens/user1_add.png"))); // NOI18N
		adicionarUsuario.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				adicionarUsuarioActionPerformed(evt);
			}
		});
		jPanel3.add(adicionarUsuario);

		removerUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/agenda/client/view/imagens/user1_delete.png"))); // NOI18N
		removerUsuario.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				removerUsuarioActionPerformed(evt);
			}
		});
		jPanel3.add(removerUsuario);

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
			jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(
				jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jScrollPane2).addGroup(
					jPanel1Layout.createSequentialGroup()
						.addGroup(
							jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
								jPanel1Layout.createSequentialGroup().addGap(27, 27, 27).addGroup(
									jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel1).addComponent(
										jLabel4)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
									jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(nomeText,
										javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE).addGroup(
										jPanel1Layout.createSequentialGroup().addComponent(dataText, javax.swing.GroupLayout.PREFERRED_SIZE, 112,
											javax.swing.GroupLayout.PREFERRED_SIZE).addGap(18, 18, 18).addComponent(jLabel3).addPreferredGap(
											javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(dataFinalText,
											javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))).addComponent(
								jLabel5)).addGap(0, 0, Short.MAX_VALUE)).addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE,
					javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()));
		jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
			jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(
				jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1).addComponent(dataText,
					javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(dataFinalText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
						javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel3)).addPreferredGap(
				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addGroup(
				jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(nomeText,
					javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(jLabel4)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel5)
				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jScrollPane2,
					javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
					javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(
					javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

		getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_START);

		jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
		jPanel2.setLayout(new java.awt.BorderLayout());

		jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

		confirmarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/agenda/client/view/imagens/add.png"))); // NOI18N
		confirmarButton.setLabel("Confirmar");
		confirmarButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				confirmarButtonActionPerformed(evt);
			}
		});
		jPanel4.add(confirmarButton);

		cancelarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/agenda/client/view/imagens/error.png"))); // NOI18N
		cancelarButton.setLabel("Cancelar");
		cancelarButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cancelarButtonActionPerformed(evt);
			}
		});
		jPanel4.add(cancelarButton);

		jPanel2.add(jPanel4, java.awt.BorderLayout.PAGE_END);

		jScrollPane3.setViewportView(arquivosJList);

		jPanel2.add(jScrollPane3, java.awt.BorderLayout.CENTER);

		adicionarArquivoButton.setText("Adicionar Arquivo");
		adicionarArquivoButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				adicionarArquivoButtonActionPerformed(evt);
			}
		});
		jPanel5.add(adicionarArquivoButton);

		removerArquivoButton.setText("Remover Arquivo");
		removerArquivoButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				removerArquivoButtonActionPerformed(evt);
			}
		});
		jPanel5.add(removerArquivoButton);

		downloadArquivoButton.setText("Download Arquivo");
		downloadArquivoButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				downloadArquivoButtonActionPerformed(evt);
			}
		});
		jPanel5.add(downloadArquivoButton);

		jPanel2.add(jPanel5, java.awt.BorderLayout.PAGE_START);

		getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_END);

		jScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
		jScrollPane1.setPreferredSize(new java.awt.Dimension(452, 150));

		contatosTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { { null, null }, { null, null }, { null, null },
			{ null, null } }, new String[] { "Usuário", "Situação" }) {
			boolean[] canEdit = new boolean[] { false, false };

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
		jScrollPane1.setViewportView(contatosTable);

		getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

		java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
		setBounds((screenSize.width - 416) / 2, (screenSize.height - 660) / 2, 416, 660);
	}// </editor-fold>//GEN-END:initComponents

	private void confirmarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmarButtonActionPerformed
		confirmar();
	}//GEN-LAST:event_confirmarButtonActionPerformed

	private void cancelarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarButtonActionPerformed
		cancelar();
	}//GEN-LAST:event_cancelarButtonActionPerformed

	private void adicionarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionarUsuarioActionPerformed
		adicionarUsuario();
	}//GEN-LAST:event_adicionarUsuarioActionPerformed

	private void removerUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removerUsuarioActionPerformed
		removerUsuario();
	}//GEN-LAST:event_removerUsuarioActionPerformed

	private void adicionarArquivoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionarArquivoButtonActionPerformed
		adicionarArquivo();
	}//GEN-LAST:event_adicionarArquivoButtonActionPerformed

	private void downloadArquivoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadArquivoButtonActionPerformed
		downloadArquivo();
	}//GEN-LAST:event_downloadArquivoButtonActionPerformed

	private void removerArquivoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removerArquivoButtonActionPerformed
		removerArquivo();
	}//GEN-LAST:event_removerArquivoButtonActionPerformed

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton adicionarArquivoButton;
	private javax.swing.JButton adicionarUsuario;
	private javax.swing.JList arquivosJList;
	private javax.swing.JButton cancelarButton;
	private javax.swing.JButton confirmarButton;
	private javax.swing.JTable contatosTable;
	private javax.swing.JFormattedTextField dataFinalText;
	private javax.swing.JFormattedTextField dataText;
	private javax.swing.JTextArea descricaoText;
	private javax.swing.JButton downloadArquivoButton;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JPanel jPanel3;
	private javax.swing.JPanel jPanel4;
	private javax.swing.JPanel jPanel5;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JScrollPane jScrollPane2;
	private javax.swing.JScrollPane jScrollPane3;
	private javax.swing.JTextField nomeText;
	private javax.swing.JButton removerArquivoButton;
	private javax.swing.JButton removerUsuario;
	// End of variables declaration//GEN-END:variables

	private Compromisso compromisso;

	private void confirmar() {
		if (validar()) {
			compromisso.setNome(nomeText.getText());
			compromisso.setDescricao(descricaoText.getText());
			compromisso.setDataInicial(StringUtils.toDate(dataText.getText(), "dd/MM/yyyy"));
			compromisso.setProprietario(PrincipalCliente.getUsuarioLogado());

			try {
				RespostaRequisicao resposta = ClienteServidor.getINSTANCIA().enviarInformacao(new VerificarChoqueCompromissoRequisicao(compromisso));
				if (resposta.isErro()) {
					showMessage(resposta.getMsg());

					if (JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(this, "Ocorreram choques no compromisso, deseja continuar?",
						"Ocorreram choques.", JOptionPane.YES_NO_OPTION))
						return;
				}
			} catch (Exception e) {
				e.printStackTrace();
				showMessage(e.getMessage());
				return;
			} finally {
				ClienteServidor.getINSTANCIA().liberarComunicacao();
			}

			try {
				RespostaRequisicao resposta = ClienteServidor.getINSTANCIA().enviarInformacao(new EnviarCompromissoRequisicao(compromisso));

				if (resposta.isErro()) {
					showMessage(resposta.getMsg());
					return;
				}

				showMessage("Compromisso agendado com sucesso.");
				dispose();
			} catch (Exception e) {
				e.printStackTrace();
				showMessage(e.getMessage());
			} finally {
				ClienteServidor.getINSTANCIA().liberarComunicacao();
			}
		}
	}

	private void showMessage(String msg) {
		JOptionPane.showMessageDialog(this, msg);
	}

	private boolean validar() {
		return true;
	}

	private void cancelar() {
		fechar();
	}

	private void fechar() {

		try {
			RespostaRequisicao respo = ClienteServidor.getINSTANCIA().enviarInformacao(new AtualizarStatusCompromissoRequisicao(""));
			if (respo.isErro())
				showMessage(respo.getMsg());
		} catch (Exception e) {
			e.printStackTrace();
			showMessage(e.getMessage());
		} finally {
			ClienteServidor.getINSTANCIA().liberarComunicacao();
		}
		dispose();
	}

	private void adicionarUsuario() {
		try {
			RespostaRequisicao resposta = ClienteServidor.getINSTANCIA().enviarInformacao(new EnvioInformacao() {
				@Override
				public Requisicao getRequisicao() {
					return new Requisicao(RequisicaoEnum.BUSCAR_USUARIOS.getId());
				}

				@Override
				public void enviar(OutputStream output) throws Exception {

				}

				@Override
				public void setSocket(Socket socket) {
				}
			});
			if (resposta.isErro()) {
				showMessage(resposta.getMsg());
				return;
			}

			List<Usuario> usuarios = (List<Usuario>) ClienteServidor.getINSTANCIA().lerObjeto();

			UsuariosListDialogView usuariosDialog = new UsuariosListDialogView(this, true);
			usuariosDialog.setLocationRelativeTo(this);
			usuariosDialog.setUsuarios(usuarios);
			usuariosDialog.setUsuariosListener(this);
			usuariosDialog.setVisible(true);

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ClienteServidor.getINSTANCIA().liberarComunicacao();
		}
	}

	private void removerUsuario() {
		JOptionPane.showMessageDialog(this, "Falta implementar.");
	}

	public void setCompromisso(Compromisso compromisso) {
		this.compromisso = compromisso;
		refreshView();
	}

	private void refreshView() {

		if (compromisso.getDataInicial() != null)
			dataText.setText(StringUtils.toStr(compromisso.getDataInicial(), "dd/MM/yyyy"));

		if (compromisso.getDataFinal() != null)
			dataFinalText.setText(StringUtils.toStr(compromisso.getDataFinal(), "dd/MM/yyyy"));

		nomeText.setText(compromisso.getNome());
		descricaoText.setText(compromisso.getDescricao());

		atualizarTabelaAnexos();
		atualizarTabelaContatos();
	}

	@Override
	public void selecionou(List<Usuario> usuarios) {

		for (Usuario usuario : usuarios) {
			if (!compromisso.isUsuarioConvidado(usuario)) {
				Convite convite = new Convite();
				convite.setUsuario(usuario);
				convite.setResposta(Convite.NAO_RESPONDIDO);
				compromisso.adicionarConvite(convite);
			}
		}

		atualizarTabelaContatos();
	}

	private void atualizarTabelaContatos() {
		DefaultTableModel modelTabela = (DefaultTableModel) contatosTable.getModel();
		Object[][] data = new Object[compromisso.getConvites().size()][2];
		int i = 0;
		for (Convite convite : compromisso.getConvites()) {
			data[i][0] = convite.getUsuario().getLoginEmail();
			String situacao = "Não Respondeu";
			if (convite.getResposta() == Convite.ACEITO)
				situacao = "Aceitou";
			else if (convite.getResposta() == Convite.RECUSADO)
				situacao = "Recusou";
			data[i][1] = situacao;
			i++;
		}
		modelTabela.setDataVector(data, new String[] { "Usuario", "Situação" });
	}

	private void atualizarTabelaAnexos() {
		ArrayList<AnexoCompromisso> anexosNaoDeletados = new ArrayList<AnexoCompromisso>();
		for (AnexoCompromisso anexoCompromisso : compromisso.getAnexos()) {
			if (!anexoCompromisso.isDeletado())
				anexosNaoDeletados.add(anexoCompromisso);
		}

		arquivosJList.setListData(anexosNaoDeletados.toArray());
	}

	private void adicionarArquivo() {
		JFileChooser chooser = new JFileChooser();
		chooser.setMultiSelectionEnabled(true);
		int abriu = chooser.showOpenDialog(this);

		if (abriu == JFileChooser.APPROVE_OPTION) {
			File[] arquivosSelecionados = chooser.getSelectedFiles();

			for (File arquivo : arquivosSelecionados) {
				AnexoCompromisso anexo = new AnexoCompromisso();
				anexo.setCaminho(arquivo.getAbsolutePath());
				anexo.setNome(arquivo.getName());
				if (!compromisso.getAnexos().contains(anexo))
					compromisso.getAnexos().add(anexo);
			}
			atualizarTabelaAnexos();
		}
	}

	private void removerArquivo() {
		Object[] anexos = arquivosJList.getSelectedValues();
		if (anexos.length > 0) {
			for (Object object : anexos) {
				if (object instanceof AnexoCompromisso) {
					AnexoCompromisso anexo = (AnexoCompromisso) object;
					anexo.setDeletado(true);
				}
			}
			atualizarTabelaAnexos();
		}
	}

	private void downloadArquivo() {
		Object[] anexos = arquivosJList.getSelectedValues();
		if (anexos.length > 0) {
			for (Object object : anexos) {
				if (object instanceof AnexoCompromisso) {
					AnexoCompromisso anexo = (AnexoCompromisso) object;
					downloadAnexo(anexo);
				}
			}
		}
	}

	private void downloadAnexo(final AnexoCompromisso anexo) {
		if (anexo.isNoSevidor()) {

			try {

				ObjectEnvioInformacao objetoEnvio = new ObjectEnvioInformacao() {
					@Override
					public Serializable getObjeto() {
						return anexo;
					}

					@Override
					public Requisicao getRequisicao() {
						return new Requisicao(RequisicaoEnum.DOWNLOAD_ANEXO.getId());
					}
				};
				RespostaRequisicao resp = ClienteServidor.getINSTANCIA().enviarInformacao(objetoEnvio);

				if (resp.isErro()) {
					showMessage(resp.getMsg());
					return;
				}

				File file = null;
				while (file == null) {

					JFileChooser jFileChooser = new JFileChooser();
					jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
					jFileChooser.showSaveDialog(CompromissoDialogView.this);
					file = jFileChooser.getSelectedFile();
				}

				file = new File(file.getAbsolutePath() + "/" + anexo.getNome());

				System.out.println("Arquivo atual " + file.getAbsolutePath());
				BufferedInputStream bufferInput = new BufferedInputStream(objetoEnvio.getSck().getInputStream(), 1024);
				BufferedOutputStream fileOutputStream = new BufferedOutputStream(new FileOutputStream(file));

				FileUtil.receber(fileOutputStream, bufferInput, objetoEnvio.getSck().getOutputStream());

				objetoEnvio.getSck().getOutputStream().write(1);

				fileOutputStream.flush();
				fileOutputStream.close();
			} catch (Exception e) {
				e.printStackTrace();
				showMessage(e.getLocalizedMessage());
				return;
			} finally {
				ClienteServidor.getINSTANCIA().liberarComunicacao();
			}

			showMessage("Download realizado com sucesso.");
		} else {
			showMessage("O arquivo ainda não foi enviado para o servidor.");
		}

	}

	public void setDisableForm(boolean b) {
		confirmarButton.setEnabled(!b);
		adicionarArquivoButton.setEnabled(!b);
		removerArquivoButton.setEnabled(!b);

		adicionarUsuario.setEnabled(!b);
		removerUsuario.setEnabled(!b);

		nomeText.setEnabled(!b);
		descricaoText.setEnabled(!b);

		dataText.setEnabled(!b);
		dataFinalText.setEnabled(!b);
	}
}
